<?php

abstract class Kd_Data_Table_Column_Base {

    private $_columnName = '';
    private $_isPrimaryKey = FALSE;
    private $_isIncrement = FALSE;
    private $_defaultValue = FALSE;
    private $_nullable = TRUE;
    private $_insertable = TRUE;
    private $_updateable = TRUE;
//    protected $rules = array();

    public function __construct() {

    }

    public function getInsertable() {
        if ($this->getIsIncrement()) {
            return FALSE;
        }
        return $this->_insertable;
    }

    public function setInsertable($value) {
        $this->_insertable = $value;
        return $this;
    }

    public function getUpdateable() {
        if ($this->getIsPrimaryKey()) {
            return FALSE;
        }
        return $this->_updateable;
    }

    public function setUpdateable($value) {
        $this->_updateable = $value;
        return $this;
    }

    public function getIsPrimaryKey() {
        return $this->_isPrimaryKey;
    }

    public function setIsPrimaryKey($value) {
        $this->_isPrimaryKey = $value;
        return $this;
    }

    public function getIsIncrement() {
        return $this->_isIncrement;
    }

    public function setIsIncrement($value) {
        $this->_isIncrement = $value;
        return $this;
    }

    public function getColumnName() {
        return $this->_columnName;
    }

    public function setColumnName($value) {
        $this->_columnName = $value;
        return $this;
    }

    public function getDefaultValue() {
        if ($this->_defaultValue !== FALSE) {
            return $this->_defaultValue;
        }
        if ($this->getIsNullable()) {
            return NULL;
        }
        return '';
    }

    public function setDefaultValue($value) {
        $this->_defaultValue = $value;
        return $this;
    }

    public function isDefaultSetted(){
        return $this->_defaultValue != FALSE;
    }

    public function getIsNullable() {
        return $this->_nullable;
    }

    public function setIsNullable($value) {
        $this->_nullable = $value;
        return $this;
    }

    public function convertToDb($value){
        return $value;
    }

    public function convertFromDb($value){
        return $value;
    }

    public abstract function validate($value);
//    {
//        switch ($this->getColumnType()) {
//            case 'datetime':
//                return!empty($value);
//            case 'integer':
//                return ctype_digit($value) || is_int($value);
//            case 'number':
//                return is_number($value);
//            default:
//                return true;
//        }
//    }

    public abstract function getColumnType();

    public abstract function getParameterName();
}